package helloworld.admin.action.news;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import helloworld.admin.assembler.news.NewsFormAssembler;
import helloworld.admin.bean.NewsAdminBean;
import helloworld.admin.form.news.NewsForm;
import helloworld.delegate.news.NewsDelegate;
import org.apache.struts.actions.DispatchAction;

/**
 * @author TUYEN-DM
 *         <p>
 *         2009/05/25
 *         </p>
 *         <p>
 *         NewsShowAction is the object representation of showing news's form.
 *         </p>
 */
public class NewsShowAction extends DispatchAction {

	public ActionForward Create(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		return mapping.findForward("newsFormPage");
	}

	public ActionForward Edit(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		
		NewsDelegate delegate = new NewsDelegate();
		NewsAdminBean news = delegate.getNewsDetail(request.getParameter("newsTitle"));
		NewsForm newsForm = NewsFormAssembler.createNewsForm(news);
		request.setAttribute("NewsForm", newsForm);
		return mapping.findForward("newsFormPage");
	}
}
